package com.csdemos;

import com.csdemos.R;
import com.csdemos.algs.SortUtils;

import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.view.Menu;
import android.view.View;

public class MainActivity extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.activity_main, menu);
        return true;
    }
    
    public void prQ(View view) {
    	startActivity(new Intent(this, PriorityQueueDemoActivity.class));
    }
    
    public void stack(View view) {
    	startActivity(new Intent(this, StackDemoActivity.class));
    }
    
    public void dStack(View view) {
    	startActivity(new Intent(this, DoubleStackDemoActivity.class));
    }
    
    public void deque(View view) {
    	startActivity(new Intent(this, DequeDemoActivity.class));
    }
    
    public void queue(View view) {
    	startActivity(new Intent(this, QueueDemoActivity.class));
    }
    
    public void binaryTree(View view) {
    	startActivity(new Intent(this, BinaryTreeDemoActivity.class));
    }
    
    public void sort(View view) {
    	int sortMethod;
    	int titleId;
    	switch (view.getId()) {
		case R.id.sort_countingSort:
			sortMethod = SortUtils.COUNTING_SORT;
			titleId = R.string.sort_countingSort;
			break;
		case R.id.sort_heapSort:
			sortMethod = SortUtils.HEAP_SORT;
			titleId = R.string.sort_heapSort;
			break;
		case R.id.sort_hoareQS:
			sortMethod = SortUtils.HOARE_QUICK_SORT;
			titleId = R.string.sort_hoareQS;
			break;
		case R.id.sort_quickSort:
			sortMethod = SortUtils.QUICK_SORT;
			titleId = R.string.sort_quickSort;
			break;
		case R.id.sort_radixSort:
			sortMethod = SortUtils.RADIX_SORT;
			titleId = R.string.sort_radixSort;
			break;
		case R.id.sort_bucketSort:
			sortMethod = SortUtils.BUCKET_SORT;
			titleId = R.string.sort_bucketSort;
			break;
		default:
			sortMethod = SortUtils.NO_SORT;
			titleId = SortActivity.SORT_METHOD_TITLE_UNKNOWN;
			break;
		}
    	Intent intent = new Intent(this, SortActivity.class);
    	intent.putExtra(SortActivity.SORT_METHOD, sortMethod);
    	intent.putExtra(SortActivity.SORT_METHOD_TITLE, titleId);
    	startActivity(intent);
    }
    
}
